package cn.snmp.mutual.org.opennms.protocols.snmp;

import java.io.*;

import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnDecodingException;
import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnEncoder;
import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnEncodingException;

public class SnmpUInt32 implements SnmpSyntax, Cloneable, Serializable {
    static final long serialVersionUID = 6360915905545058942L;
    private long m_value;
    private static final long MASK = 4294967295L;
    public static final byte ASNTYPE = 66;

    public SnmpUInt32() {
        this.m_value = 0L;
    }

    public SnmpUInt32(final long value) {
        this.m_value = (value & 0xFFFFFFFFL);
    }

    public SnmpUInt32(final Long value) {
        this((long) value);
    }

    public SnmpUInt32(final SnmpUInt32 second) {
        this.m_value = second.m_value;
    }

    public long getValue() {
        return this.m_value & 0xFFFFFFFFL;
    }

    public void setValue(final long value) {
        this.m_value = (value & 0xFFFFFFFFL);
    }

    public void setValue(final Long value) {
        this.m_value = ((long) value & 0xFFFFFFFFL);
    }

    public byte typeId() {
        return 66;
    }

    public int encodeASN(final byte[] buf, final int offset, final AsnEncoder encoder) throws AsnEncodingException {
        return encoder.buildUInteger32(buf, offset, this.typeId(), this.getValue());
    }

    public int decodeASN(final byte[] buf, final int offset, final AsnEncoder encoder) throws AsnDecodingException {
        final Object[] rVals = encoder.parseUInteger32(buf, offset);
        if ((byte) rVals[1] != this.typeId()) {
            throw new AsnDecodingException("Invalid ASN.1 type");
        }
        this.setValue((Long) rVals[2]);
        return (int) rVals[0];
    }

    public SnmpSyntax duplicate() {
        return new SnmpUInt32(this);
    }

    public Object clone() {
        return new SnmpUInt32(this);
    }

    @Override
    public String toString() {
        return String.valueOf(this.getValue());
    }
}
